//
//  SettingVC.m
//  MyProject
//
//  Created by jiaming yan on 2018/5/15.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "SettingVC.h"
#import "ModifyPhoneVC.h"
#import <Hyphenate/Hyphenate.h>
#import "NSUDManager.h"
#import "AppDelegate.h"
#import "AboutUsVC.h"

#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>

#import "AppDelegate.h"
#import "WebViewController.h"

@interface SettingVC ()
@property (weak, nonatomic) IBOutlet UISwitch *motifiSwitch;
@property (weak, nonatomic) IBOutlet UILabel *versonLabel;

@end

@implementation SettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"设置";
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    // app版本
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    self.versonLabel.text = [NSString stringWithFormat:@"V%@",app_Version];
    NSInteger sysVersion = [UIDevice currentDevice].systemVersion.integerValue;
    if(sysVersion<8) {
        if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == 0) {
            self.motifiSwitch.on = NO;
        }else {
             self.motifiSwitch.on = YES;
        }
    }else {
        if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == 0) {
            self.motifiSwitch.on = NO;
        }else {
            self.motifiSwitch.on = YES;
        }
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)modifyMobileClick:(id)sender {
    ModifyPhoneVC *vc = [[ModifyPhoneVC alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)notifyChange:(UISwitch*)sender {
    NSURL * url = [NSURL URLWithString:@"taijienotice:root=NOTIFICATIONS_ID"];
    
    if ( [[UIApplication sharedApplication] canOpenURL: url] ) {
        
        NSURL*url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        
        [[UIApplication sharedApplication] openURL:url];
    }
}
- (IBAction)serviceClick:(id)sender {
    WebViewController *vc = [[WebViewController alloc]init];
    vc.titleStr =@"用户协议";
    vc.url = [NSString stringWithFormat:@"%@%@",ImageBaseURL,@"台阶网用户协议.docx"];
    vc.isWord = YES;
    [self.navigationController pushViewController:vc animated:YES];

}
- (IBAction)aboutUsClick:(id)sender {
    AboutUsVC *vc = [[AboutUsVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)logoutClick:(id)sender {
//    __weak typeof(self) weakSelf = self;
    [self showProgressWithView:self.view animated:YES];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         [[EMClient sharedClient]  logout:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self hideProgress:self.view animated:YES];
            
           
            [NSUDManager setCurrentUser:nil];
            
            KUSERDEFAULTS;
            [defaults removeObjectForKey:@"currentUser"];
            [defaults synchronize];
            
            [(AppDelegate *)([UIApplication sharedApplication].delegate) gotoLogin];
        });
        
    });
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
